package com.yal.controller;

import com.alibaba.fastjson.JSON;
import com.yal.domian.Product;
import com.yal.entity.HealthCard;
import com.yal.service.HealthCardService;
import com.yal.service.impl.ProductServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("produce")
@Slf4j
public class ProductController {

    @Autowired
    private ProductServiceImpl psi;

    @Autowired
    private HealthCardService healthCardService;

    //商品信息查询
    @RequestMapping("/findByIdForProduct/{pid}")
    public Product findProduct(@PathVariable("pid") Integer id) {
        System.out.println("准备查询商品信息...");
        System.out.println("查询商品信息的编号为："+id);
        Product product = psi.findById(id);
        log.info("查询成功{}",JSON.toJSONString(product));
        return product;
    }

    @RequestMapping("/findAllHealthCard")
    public List<HealthCard> findAllHealthCard(){
        List<HealthCard> healthCards = healthCardService.findAll();
        log.info("集合中的size:"+healthCards.size());
        return healthCards;
    }
}
